package com.hxiaoyi.cloud.service.impl;

import cn.hutool.core.lang.UUID;
import com.hxiaoyi.cloud.service.IMessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

/**
 * IMessageProvider实现类
 * EnableBinding 定义消息的推送管道
 * @author 黄敬意
 * @date 2022-03-05 19:05
 **/
@EnableBinding(Source.class)
@Slf4j
public class MessageProviderImpl implements IMessageProvider {
    /**消息发送管道*/
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        String value = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(value).build());
        log.info("----------value消息:" + value);
        return "------已发送消息：" + value;
    }
}
